"""
    @Author  ：思念 
    @File    ：7.通过生产者消费者模式创建进程.py
    @Date    ：2025/3/12 10:51 
"""

from multiprocessing import Process,Queue
import time

def worker_1(q):
    for i in range(1,6):
        q.put(i)
        print("生产者：", i)
        time.sleep(0.5)
    q.put(None)


def worker_2(q):
    while True:
        i = q.get()
        if i is not None:
            print("消费者：", i)
            time.sleep(0.5)
        else:
            break

if __name__ == '__main__':
    queue = Queue()
    p1 = Process(target=worker_1, args=(queue,))
    p2 = Process(target=worker_2, args=(queue,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()

    print("主进程结束")

